home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 19 / CU Amiga Magazine's Super CD-ROM 19 (1998)(EMAP Images)(GB)[!][issue 1998-02].iso / CUCD / Programming / LEDA / incl / LEDA.020+881 / d3_dictionary.h < prev    next >
C/C++ Source or Header  |  1994-08-05  |  4KB  |  123 lines

  1. /*******************************************************************************
  2. +
  3. +  LEDA  3.1c
  4. +
  5. +
  6. +  d3_dictionary.h
  7. +
  8. +
  9. +  Copyright (c) 1994  by  Max-Planck-Institut fuer Informatik
  10. +  Im Stadtwald, 6600 Saarbruecken, FRG     
  11. +  All rights reserved.
  12. *******************************************************************************/
  13.  
  14.  
  15.  
  16. #ifndef LEDA_d3_dictionary_H
  17. #define LEDA_d3_dictionary_H
  18.  
  19. #include <LEDA/impl/range_tree.h>
  20. typedef rt_item dic3_item;
  21.  
  22.  
  23.  
  24. template<class type1, class type2, class type3, class itype>
  25. class _CLASSTYPE d3_dictionary : public range_tree {
  26.  
  27.   // redefine the virtual functions of class range_tree
  28.  
  29.   void rt_clear_key(GenPtr*& x) const { 
  30.     Clear(ACCESS(type1,x[0])); Clear(ACCESS(type2,x[1])); 
  31.     Clear(ACCESS(type3,x[2])); 
  32.   }
  33.   
  34.   void rt_copy_key(GenPtr*& x) const { 
  35.     Copy(ACCESS(type1,x[0])); Copy(ACCESS(type2,x[1])); 
  36.     Copy(ACCESS(type3,x[2])); 
  37.   }
  38.  
  39.   void rt_print_key(int d,GenPtr*& x) const {
  40.     switch(d) {
  41.       case 0: Print(ACCESS(type1,x[0]),cout);
  42.                 break;
  43.       case 1: Print(ACCESS(type2,x[1]),cout);
  44.                 break;
  45.       case 2: Print(ACCESS(type3,x[2]),cout);
  46.                 break;
  47.     }
  48.   }
  49.  
  50.   void rt_clear_inf(GenPtr& x) const { Clear(ACCESS(itype,x));}
  51.   void rt_copy_inf(GenPtr& x) const { Copy(ACCESS(itype,x));}
  52.  
  53.   int rt_cmp(int d, GenPtr* p, GenPtr* q) const { 
  54.     switch(d) {
  55.       case 0: return compare(ACCESS(type1,p[0]),ACCESS(type1,q[0]));
  56.       case 1: return compare(ACCESS(type2,p[1]),ACCESS(type2,q[1]));
  57.       case 2: return compare(ACCESS(type3,p[2]),ACCESS(type3,q[2]));
  58.     }
  59.   }
  60.  
  61.   range_tree* new_range_tree(int dim, int lev) { 
  62.     return new d3_dictionary<type1,type2,type3,itype>(lev); 
  63.   }
  64.  
  65.   public:
  66.   
  67.     d3_dictionary( int lev=0 ) : range_tree(3,lev) {}
  68.     ~d3_dictionary() { clear(); }
  69.   
  70.     itype inf(dic3_item x)    { return ACCESS(itype,x->inf()); }
  71.     type1 key1(dic3_item x)   { return ACCESS(type1,x->key(0)); }
  72.     type2 key2(dic3_item x)   { return ACCESS(type2,x->key(1)); }
  73.     type3 key3(dic3_item x)   { return ACCESS(type3,x->key(2)); }
  74.   
  75.   
  76.     void  change_inf(dic3_item x, itype i) { 
  77.       Clear(ACCESS(itype,x->inf())); 
  78.       x->inf() = Copy(i); 
  79.     }
  80.   
  81.     dic3_item min_key1() { return range_tree::rt_min(0); }
  82.     dic3_item max_key1() { return range_tree::rt_max(0); }
  83.     dic3_item min_key2() { return range_tree::rt_min(1); }
  84.     dic3_item max_key2() { return range_tree::rt_max(1); }
  85.     dic3_item min_key3() { return range_tree::rt_min(2); }
  86.     dic3_item max_key3() { return range_tree::rt_max(2); }
  87.   
  88.     dic3_item insert(type1 x,type2 y,type3 z,itype i)
  89.     { 
  90.       rt_item p = new rt_elem(Copy(x),Copy(y),Copy(z),Copy(i));
  91.       return range_tree::insert(p);
  92.      }
  93.     
  94.     list<rt_item> range_search( type1 x0, type1 x1,
  95.                       type2 y0, type2 y1,
  96.                       type3 z0, type3 z1 )
  97.     { 
  98.       rt_elem p(Convert(x0),Convert(y0),Convert(z0),0);
  99.       rt_elem q(Convert(x1),Convert(y1),Convert(z1),0);
  100.       return range_tree::query(&p,&q);
  101.     }
  102.   
  103.     dic3_item lookup( type1 x, type2 y, type3 z ) { 
  104.       rt_elem p(Convert(x),Convert(y),Convert(z),0);
  105.       return range_tree::lookup(&p);
  106.     }
  107.   
  108.     void del(type1 x,type2 y, type3 z) { 
  109.       rt_elem p(Convert(x),Convert(y),Convert(z),0);
  110.       range_tree::del(&p);
  111.      }
  112.   
  113.     void del_item(dic3_item it) { range_tree::del(it); }
  114.     list<dic3_item> all_items() { return range_tree::all_items(); }
  115. };
  116.  
  117. // iteration macro
  118. //
  119. #define forall_dic3_items(x,T)  (T).init_iteration(); forall(x,(T).L )
  120.  
  121. #endif
  122.